package org.shel.service

import javax.ws.rs.{GET, POST, Path, PathParam, Consumes, Produces}
import javax.ws.rs.core.PathSegment;

import org.shel.data

/**
 * The ReST API that exposes the player resource
 */
@Path("/api/v1/")
@Produces({ "application/json" })
@Consumes({ "application/json" })
class PlayerResource {

    val database:PlayerDaoTrait
    
    @GET
    @Path("/player/")
    @Produces({ "application/json" })
    def getPlayers() = database.list
    
    @POST
    @Path("/player/")
    @Consumes({ "application/json" })
    @Produces({ "application/json" })
    def insertPlayer() =
        val player = ...
        database.insert(player)
    
    @GET
    @Path("/player/{id}")
    @Produces({ "application/json" })
    def getPlayer(@PathParam("id") id : PathSegment) =
        database.get(id.getPath())
    
    @POST
    @Path("/player/{id}")
    @Consumes({ "application/json" })
    @Produces({ "application/json" })
    def updatePlayer(@PathParam("id") id : PathSegment) =
        val player = ...
        database.update(player)
    
    @GET
    @Path("/player/{id}/history")
    @Produces({ "application/json" })
    def getHistory(@PathParam("id") id : PathSegment) =
        database.getHistory(id.getPath(), 30)
}
